package ace.tool.generate.code.impl.resolver.scheme.resolver.core;

import ace.tool.generate.code.impl.resolver.scheme.model.bo.core.test.TestBaseTestClassInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.ClassFileInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.CommonInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.ProjectInfo;
import ace.tool.generate.code.impl.resolver.scheme.resolver.ClassFileInfoResolver;
import ace.tool.generate.code.impl.service.model.input.GenerateInput;
import java.util.HashMap;
import java.util.Map;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import org.apache.commons.text.StringSubstitutor;

/**
 * @author caspar
 * @date 2023/11/17 10:34
 */
@Builder
@RequiredArgsConstructor
public class TestBaseTestClassInfoResolver {
  private final GenerateInput input;
  private final ProjectInfo coreProjectInfo;
  private final CommonInfo commonInfo;

  public TestBaseTestClassInfo resolve() {

    ClassFileInfo classFileInfo =
        ClassFileInfoResolver.builder()
            .className(this.getClassName())
            .classNameSuffix("")
            .classPackagePrefix(input.getTestRootPackagePrefix())
            .rootPackageFullName(commonInfo.getRootPackageFullName())
            .sourceCodeRootDir(coreProjectInfo.getTestSourceCodeRootDir())
            .build()
            .resolve();

    return TestBaseTestClassInfo.builder().info(classFileInfo).build();
  }

  private String getClassName() {
    Map<String, String> data = new HashMap<>();
    data.put("className", "BaseTest");
    return StringSubstitutor.replace("${className}", data);
  }
}
